package com.net.tcp;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;

/**
 * @author Li
 * @Date 2023/4/23 19:23
 */
public class TCPClient {
    public static void main(String[] args) throws IOException {
        System.out.println("客户端启动");
//        创建客服端socket
        Socket socket = new Socket("127.0.0.1", 30000);
//        准备发送的信息
        String message = "你好服务器";
//        首先获取输出流
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
        writer.write(message);
        writer.newLine();
        writer.flush();
//        OutputStream outputStream = socket.getOutputStream();
//        数据来源
//        outputStream.write(message.getBytes());
        System.out.println("客户端发送完毕");
//        关闭流
        writer.close();
        socket.close();
    }
}
